package com.token.sysflow.core;
import com.token.sql.IntegrateSql;
import com.token.sysflow.exception.ErrorCodeEnum;
import com.token.sysflow.exception.FlowException;
import com.token.sysflow.hander.Notify;
import com.token.sysflow.impl.AbstractFlowHandlerImpl;

import java.util.List;

/**
 * 催办
 * @author chenjianxiong 2020/4/13
 */
public class UrgFlow extends AbstractFlowCore{
    public UrgFlow(IntegrateSql f, String keyUnid) throws Exception{
        super(f,keyUnid);
    }


    @Override
    public void execute(AbstractFlowHandlerImpl flowHandler) throws Exception{

        //检查流程状态，结束和终止不允许操作
        checkFlowStatus();

        //判断当前用户是否是当前申请人
        if (!approveProcess.getApplyer().equals(flowHandler.getActionUser()) || !approveProcess.getCreater().equals(flowHandler.getActionUser())) {
            throw new FlowException(ErrorCodeEnum.APPLYER_CHECK);
        }

        List<String> arraylist = approveProcess.getApproves(approveProcess.getStepId());


        //处理知会
        Notify notify = new Notify(this.getISql());
        notify.setSubject("流程催办【"+ approveProcess.getFlowNo() + "】");
        notify.setMessage(flowHandler.getOpinions());
        notify.setActionUserId(flowHandler.getActionUser());
        notify.setSendUsers(arraylist);
        notify.setStep(approveProcess.getStep());
        notify.insertSystemNotify();
        notify.close();

    }
}
